<template>
  <div class="register-container">
    <h2>注册</h2>
    <form @submit.prevent="handleRegister">
      <div class="input-group">
        <label for="username">用户名</label>
        <input v-model="username" id="username" type="text" required />
      </div>
      <div class="input-group">
        <label for="password">密码</label>
        <input v-model="password" id="password" type="password" required />
      </div>
      <div class="input-group">
        <label for="confirmPassword">确认密码</label>
        <input v-model="confirmPassword" id="confirmPassword" type="password" required />
      </div>
      <button type="submit">注册</button>
      <p>已有账号？<router-link to="/login">登录</router-link></p>
    </form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      email: '',
      password: '',
      confirmPassword: ''
    };
  },
  methods: {
    handleRegister() {
      if (this.password !== this.confirmPassword) {
        alert('密码不匹配');
        return;
      }
      // 这里可以添加实际的注册请求逻辑
      alert(`注册成功！用户名：${this.username}`);
    }
  }
};
</script>

<style scoped>
.register-container {
  max-width: 400px;
  margin: auto;
  padding: 20px;
  background-color: #f9f9f9;
  border-radius: 5px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.input-group {
  margin-bottom: 15px;
}
input {
  width: 100%;
  padding: 8px;
  margin-top: 5px;
}
button {
  width: 100%;
  padding: 10px;
  background-color: #4caf50;
  color: white;
  border: none;
  cursor: pointer;
}
button:hover {
  background-color: #45a049;
}
</style>
